import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);
// 定义state在vuex中存储数据
var state = {
    message: '我的键盘坏掉了',
    applies: []
};
// mutations里面放方法，用于改变state的值
var mutations = {// mutations单词不可以自定义，否则无效
    changeMessage: function(state, res) {
        // console.log("res:"+res);
        state.applies = (res);
        console.log('changeMessage state.applies:');
        console.log(state.applies);
    },
    handleRead: function(state, index) {
        // console.log("进入vuex中的handleRead："+index);
        // console.log("handleRead state.applies:"+state.applies);
        // state.applies.splice(index,1);
        console.log('handleRead state.applies:');
        console.log(state.applies);
    }
};
// 3.实例化Vuex.store
const store = new Vuex.Store({
    // state:state
    state,//简写
    mutations
});
// 4.把store暴露出去
export default store;